package gov.kqqzyyy.monkey.orderpad.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import gov.kqqzyyy.monkey.orderpad.R;


/**
 * Created by Monkey on 2017/9/6.
 * 菜品分组适配器
 */

public class OrderGroupTitleAdapter extends BaseAdapter {

    private final LayoutInflater inflater;
    private List<String> list;

    public OrderGroupTitleAdapter(Context context) {
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<String> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        if (list != null) {
            return list.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_ordermenu_grouptitle, parent, false);
            holder.mGroutTitleView = convertView.findViewById(R.id.group_title_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (list != null && list.size() > 0) {
            if (list.get(position) != null) {
                holder.mGroutTitleView.setText(list.get(position));
            }
        }
        return convertView;
    }

    class ViewHolder {
        private TextView mGroutTitleView;
    }
}
